package com.example.zhaojianxu.signin.englishgame.recording

import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.util.Log
import android.view.View
import com.example.zhaojianxu.signin.R
import com.example.zhaojianxu.signin.bean.BaseActivity
import com.example.zhaojianxu.signin.common.http.HttpUtil
import com.example.zhaojianxu.signin.englishgame.http.EGRecordEntity
import kotlinx.android.synthetic.main.activity_record.*
import kotlinx.android.synthetic.main.common_title_bar.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class RecordActivity : BaseActivity() {

    var mAdapter: RecordAdapter? = null

    override fun initView() {
        common_back.setOnClickListener {
            finish()
        }
        common_setting.visibility = View.GONE
        common_title.text = "排行榜"

        val linearLayoutManager = LinearLayoutManager(this)
        linearLayoutManager.orientation = LinearLayoutManager.VERTICAL
        activity_record_1.layoutManager = linearLayoutManager

        mAdapter = RecordAdapter()
        activity_record_1.adapter = mAdapter
    }

    override fun initData() {
        HttpUtil.instance.getEnglishGameApi()?.postQueryRecord()
            ?.enqueue(object : Callback<MutableList<EGRecordEntity>> {
                override fun onFailure(call: Call<MutableList<EGRecordEntity>>, t: Throwable) {
                    Log.e("RecordActivity","${t.message}")
                }

                override fun onResponse(call: Call<MutableList<EGRecordEntity>>, response: Response<MutableList<EGRecordEntity>>) {
                    if (response.isSuccessful && response.body() != null && response.body()?.isEmpty() == false){
                        mAdapter?.bindData(response.body()!!)
                    }
                }

            })

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_record)
    }
}
